package com.agp.config;

import com.agp.interceptor.JwtTokenInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private JwtTokenInterceptor jwtTokenInterceptor;

    /**
     * 注册自定义拦截器
     *
     * @param registry
     */

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtTokenInterceptor)
                .addPathPatterns("/common/**")
                .addPathPatterns("/user/**")                  // 拦截所有请求
                .excludePathPatterns("/user/login")  // 放行登录接口
                .excludePathPatterns("/user/register")        // 放行注册接口
                .excludePathPatterns("/common/sendCaptcha")    // 放行发送验证码接口
                ;


    }

}
